from django.db import models


# Create your models here.

class Stack(models.Model):
    """
    股票代码

    """
    s_id = models.CharField(max_length=32, primary_key=True)
    s_hcode = models.CharField(max_length=32, unique=True, verbose_name="H股代码")
    s_acode = models.CharField(max_length=32, verbose_name="A股代码")
    s_name = models.CharField(max_length=32, unique=True, null=False, verbose_name="公司名称")
    s_flag_refresh = models.IntegerField(default=0, null=False, choices=((0, "不实时更新"), (1, "实时更新")),
                                         verbose_name="更新标志位")
    s_createtime = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    s_updatetime = models.DateTimeField(auto_now=True, verbose_name="上次更新时间")
    s_20mean = models.FloatField(default=0.0, verbose_name="20天平均")
    s_flag = models.IntegerField(default=0, null=False,
                                 choices=((0, "持股"), (1, "持股"), (2, "买A卖H"), (3, "卖A买H"), (-1, "异常")),
                                 verbose_name="状态")

    class Meta:
        verbose_name = '股票'  # 控制管理处的中文显示
        verbose_name_plural = '股票'

    def __str__(self):  # 用于外键选择下拉框
        return str(self.s_hcode) + " " + self.s_name


class ConvBond(models.Model):
    """
    债券

    """
    cb_id = models.CharField(max_length=32, primary_key=True)
    cb_code = models.CharField(max_length=32, unique=True, verbose_name="债券代码")
    cb_name = models.CharField(max_length=32, unique=True, verbose_name="债券名称")
    cb_flag_refresh = models.IntegerField(default=0, null=False, choices=((0, "不实时更新"), (1, "实时更新")),
                                          verbose_name="更新标志位")
    cb_createtime = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    cb_updatetime = models.DateTimeField(auto_now=True, verbose_name="上次更新时间")
    cb_flag = models.IntegerField(default=0, null=False, choices=((0, "持可转债"), (1, "买可转债A"), (2, "买可转债B"), (-1, "异常")),
                                  verbose_name="状态")

    class Meta:
        verbose_name = '债券'  # 控制管理处的中文显示
        verbose_name_plural = '债券'


class Fund(models.Model):
    """
    股票代码

    """
    f_id = models.CharField(max_length=32, primary_key=True)
    f_name = models.CharField(max_length=32, verbose_name="基金名称")
    f_code = models.CharField(max_length=32, unique=True, verbose_name="基金代码")
    f_flag_refresh = models.IntegerField(default=0, null=False, choices=((0, "不实时更新"), (1, "实时更新")),
                                         verbose_name="更新标志位,0不实时更新，1实时更新")
    f_createtime = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    f_updatetime = models.DateTimeField(auto_now=True, verbose_name="上次更新时间")
    f_type = models.CharField(max_length=32, verbose_name="基金类型")
    f_flag = models.IntegerField(default=0, null=False, choices=((0, "买入"), (1, "卖出"), (-1, "异常")),
                                 verbose_name="状态")

    class Meta:
        verbose_name = '基金'  # 控制管理处的中文显示
        verbose_name_plural = '基金'

    def __str__(self):  # 用于下拉框
        return str(self.f_code) + " " + self.f_name
